﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.Revit;
//using HYElectricSystemSetting;

namespace HYRElectric.PowerSystem
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	public class CmdDrawingSystemGraph : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			this.uiDoc = commandData.Application.ActiveUIDocument;
			try
			{
				this.InitParameters();
				this.GetAllPanelAndPowerValue();
				if (this.isGetPara != 0)
				{
					return Autodesk.Revit.UI.Result.Failed;
				}
				if (!this.WriteXml(this.allPowerAndPanel))
				{
					MessageBox.Show("数据写入文件失败！", "盈建科提示");
					return Autodesk.Revit.UI.Result.Failed;
				}
				if (!new SystemDiagramOperate().Execute(this.uiDoc))
				{
					return Autodesk.Revit.UI.Result.Failed;
				}
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private void InitParameters()
		{
			this.vecLayingMode.Add("WE");
			this.vecLayingMode.Add("DB");
			this.vecLayingMode.Add("TC");
			this.vecLayingMode.Add("BC");
			this.vecLayingMode.Add("CLC");
			this.vecLayingMode.Add("WC");
			this.vecLayingMode.Add("CE");
			this.vecLayingMode.Add("CC");
			this.vecLayingMode.Add("SCE");
			this.vecLayingMode.Add("SR");
			this.vecLayingMode.Add("BE");
            //this.vecPipeType = this.data.GetConduitType();
			CStandardManual.GetAllSwitchLocalName(ref this.vecLocalName);
			CStandardManual.GetAllSwitchType(ref this.vecSwitchType);
            //this.vecWireType = this.data.GetWireType();
		}

		private bool WriteXml(List<CSystemDataBlock> allPowerAndPanel)
		{
			bool result;
			try
			{
				if (allPowerAndPanel.Count > 0)
				{
					XmlDocument xmlDocument = new XmlDocument();
					XmlDeclaration newChild = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null);
					xmlDocument.AppendChild(newChild);
					XmlElement newChild2 = xmlDocument.CreateElement("Boot");
					xmlDocument.AppendChild(newChild2);
					XmlNode xmlNode = xmlDocument.SelectSingleNode("Boot");
					XmlElement xmlElement = xmlDocument.CreateElement("DataItems");
					foreach (CSystemDataBlock csystemDataBlock in allPowerAndPanel)
					{
						XmlElement xmlElement2 = xmlDocument.CreateElement("DataItem");
						xmlElement2.SetAttribute("GUID", csystemDataBlock.StrGUID);
						xmlElement2.SetAttribute("DataType", csystemDataBlock.NDataType.ToString());
						if (csystemDataBlock.NDataType == 0)
						{
							FamilyInstance familyInstance = csystemDataBlock.M_object as FamilyInstance;
							xmlElement2.SetAttribute("Prefix", familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NAMING).AsInteger().ToString());
							xmlElement2.SetAttribute("Num", csystemDataBlock.StrNum);
						}
						else
						{
							FamilyInstance baseEquipment = (csystemDataBlock.M_object as ElectricalSystem).BaseEquipment;
							int num = baseEquipment.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NAMING).AsInteger();
							string text = "";
							switch (num)
							{
							case 0:
								text = baseEquipment.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX).AsString();
								text += baseEquipment.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX_SEPARATOR).AsString();
								break;
							case 2:
								text = baseEquipment.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_NAME).AsString();
								text += baseEquipment.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX_SEPARATOR).AsString();
								break;
							case 3:
								text = csystemDataBlock.StrPhase;
								break;
							}
							string value;
							try
							{
								value = csystemDataBlock.StrNum.Remove(0, text.Length);
							}
							catch (Exception)
							{
								value = csystemDataBlock.StrNum;
							}
							xmlElement2.SetAttribute("Prefix", text);
							xmlElement2.SetAttribute("Num", value);
						}
						xmlElement2.SetAttribute("LoadType", csystemDataBlock.StrLoadType);
						xmlElement2.SetAttribute("Phase", csystemDataBlock.StrPhase);
						xmlElement2.SetAttribute("Pe", csystemDataBlock.DPe.ToString());
						xmlElement2.SetAttribute("Ur", csystemDataBlock.DUr.ToString());
						xmlElement2.SetAttribute("Kx", csystemDataBlock.DKx.ToString());
						xmlElement2.SetAttribute("Cos", csystemDataBlock.DCos.ToString());
						xmlElement2.SetAttribute("Ic", csystemDataBlock.DIc.ToString());
						xmlElement2.SetAttribute("WireType", csystemDataBlock.StrWireType);
						xmlElement2.SetAttribute("WireNum", csystemDataBlock.NWireNum.ToString());
						xmlElement2.SetAttribute("Laying", csystemDataBlock.StrLaying);
						xmlElement2.SetAttribute("WireS", csystemDataBlock.DWireS.ToString());
						xmlElement2.SetAttribute("PipeType", csystemDataBlock.StrPipeType);
						xmlElement2.SetAttribute("PipeDia", csystemDataBlock.DPipeDia.ToString());
						string value2 = "";
						CStandardManual.GetSwitchNameByLocalName(csystemDataBlock.StrSwitchName, ref value2);
						xmlElement2.SetAttribute("SwitchName", value2);
						if (CStandardManual.IsSeparate(csystemDataBlock.StrSwitchType))
						{
							xmlElement2.SetAttribute("SwitchType", csystemDataBlock.StrSwitchType + "-");
						}
						else
						{
							xmlElement2.SetAttribute("SwitchType", csystemDataBlock.StrSwitchType);
						}
						xmlElement2.SetAttribute("SwitchSpec", csystemDataBlock.StrSwitchSpec);
						xmlElement2.SetAttribute("ParentGUID", csystemDataBlock.StrParentGUID);
						xmlElement.AppendChild(xmlElement2);
					}
					xmlNode.AppendChild(xmlElement);
					xmlDocument.Save(this.xmlFile);
					result = true;
				}
				else
				{
					result = false;
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private void GetAllPanelAndPowerValue()
		{
			ICollection<Element> collection = new FilteredElementCollector(this.uiDoc.ActiveView.Document).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_ElectricalEquipment).ToElements();
			if (collection.Count > 0)
			{
				this.AllPowerEquipment();
				foreach (Element element in collection)
				{
					List<ElementId> list = new List<ElementId>();
					bool flag = false;
					list.Clear();
					foreach (FindPowerAndPanel findPowerAndPanel in this.equSet)
					{
						if (findPowerAndPanel.PanelId == element.Id)
						{
							flag = true;
							if (!list.Contains(findPowerAndPanel.PowerId))
							{
								list.Add(findPowerAndPanel.PowerId);
							}
						}
					}
					if (this.powerList.Count > 0)
					{
						this.powerList.Clear();
					}
					if (list.Count > 0)
					{
						foreach (ElementId power in list)
						{
							try
							{
								this.GetDataOfPower(element, power);
							}
							catch (Exception)
							{
								MessageBox.Show("获取回路参数信息失败！", "盈建科提示");
								this.isGetPara++;
								return;
							}
						}
					}
					if (flag)
					{
						try
						{
							this.GetDataOfPanel(element);
						}
						catch (Exception)
						{
							MessageBox.Show("获取配电箱参数信息失败！", "盈建科提示");
							this.isGetPara++;
						}
					}
				}
			}
		}

		public void AllPowerEquipment()
		{
			this.equSet.Clear();
			foreach (Element element in new FilteredElementCollector(this.uiDoc.ActiveView.Document).OfClass(typeof(FamilyInstance)).ToElements())
			{
				FamilyInstance familyInstance = element as FamilyInstance;
				ElectricalSystemSet electricalSystems = familyInstance.MEPModel.ElectricalSystems;
				bool flag = false;
				try
				{
					ConnectorSetIterator connectorSetIterator = familyInstance.MEPModel.ConnectorManager.Connectors.ForwardIterator();
					while (connectorSetIterator.MoveNext())
					{
						if ((connectorSetIterator.Current as Connector).Domain == (Autodesk.Revit.DB.Domain)2)
						{
							flag = true;
							break;
						}
					}
				}
				catch (Exception)
				{
					continue;
				}
				if (flag && !string.IsNullOrEmpty(familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM).AsString()) && electricalSystems != null)
				{
					foreach (object obj in electricalSystems)
					{
						ElectricalSystem electricalSystem = (ElectricalSystem)obj;
						if (!this.equSet.Contains(new FindPowerAndPanel
						{
							PowerId = electricalSystem.Id,
							PanelId = electricalSystem.BaseEquipment.Id
						}))
						{
							this.equSet.Add(new FindPowerAndPanel
							{
								PowerId = electricalSystem.Id,
								PanelId = electricalSystem.BaseEquipment.Id
							});
						}
					}
				}
			}
		}

		private void GetDataOfPower(Element panelEle, ElementId power)
		{
			FamilyInstance familyInstance = panelEle as FamilyInstance;
			CSystemDataBlock csystemDataBlock = new CSystemDataBlock();
			Element elementById = this.uiDoc.ActiveView.Document.GetElementById(power);
			ElectricalSystem electricalSystem = elementById as ElectricalSystem;
			ElementSet elements = electricalSystem.Elements;
			csystemDataBlock.M_object = elementById;
			csystemDataBlock.NDataType = 1;
			csystemDataBlock.StrGUID = electricalSystem.Id.ToString();
			csystemDataBlock.StrNum = electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsString();
			csystemDataBlock.StrLoadType = electricalSystem.get_Parameter(BuiltInParameter.CIRCUIT_LOAD_CLASSIFICATION_PARAM).AsString();
			double num = electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEA).AsDouble();
			double num2 = electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEB).AsDouble();
			double num3 = electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEC).AsDouble();
			if (num != 0.0 && num2 == 0.0 && num3 == 0.0)
			{
				csystemDataBlock.StrPhase = "A";
			}
			else if (num2 != 0.0 && num == 0.0 && num3 == 0.0)
			{
				csystemDataBlock.StrPhase = "B";
			}
			else if (num3 != 0.0 && num2 == 0.0 && num == 0.0)
			{
				csystemDataBlock.StrPhase = "C";
			}
			else
			{
				csystemDataBlock.StrPhase = "3P";
			}
			try
			{
				double num4 = 0.0;
				foreach (object obj in elements)
				{
					FamilyInstance familyInstance2 = ((Element)obj) as FamilyInstance;
					double num5 = UnitConvert.CovertFromAPI((DisplayUnitType)84, familyInstance2.Symbol.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD).AsDouble());
					if (num5 != 0.0)
					{
						num4 += num5;
					}
				}
				if (num4 <= 0.0)
				{
					csystemDataBlock.DPe = UnitConvert.CovertFromAPI((DisplayUnitType)84, electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD).AsDouble());
				}
				else
				{
					csystemDataBlock.DPe = num4;
				}
			}
			catch (Exception)
			{
				csystemDataBlock.DPe = UnitConvert.CovertFromAPI((DisplayUnitType)84, electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD).AsDouble());
			}
            csystemDataBlock.DUr = Math.Round(UnitConvert.CovertFromAPI((DisplayUnitType)72, electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_VOLTAGE).AsDouble()));
			csystemDataBlock.DKx = Math.Round(familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_TOTAL_DEMAND_FACTOR_PARAM).AsDouble(), 2);
			csystemDataBlock.DCos = Math.Round(electricalSystem.get_Parameter(BuiltInParameter.RBS_ELEC_POWER_FACTOR).AsDouble(), 2);
			double num6 = csystemDataBlock.DKx * csystemDataBlock.DPe;
			double num7 = num6 * (Math.Sqrt(1.0 - csystemDataBlock.DCos * csystemDataBlock.DCos) / csystemDataBlock.DCos);
			double num8 = Math.Sqrt(num6 * num6 + num7 * num7);
			double dic;
			if (csystemDataBlock.StrPhase == "3P")
			{
				dic = Math.Round(num8 / (Math.Sqrt(3.0) * csystemDataBlock.DUr), 2);
			}
			else
			{
				dic = Math.Round(num8 / csystemDataBlock.DUr, 2);
			}
			csystemDataBlock.DIc = dic;
			try
			{
				csystemDataBlock.StrWireType = electricalSystem.GetParameter("导线类型").AsString();
				if (string.IsNullOrEmpty(csystemDataBlock.StrWireType))
				{
					csystemDataBlock.StrWireType = this.vecWireType[0];
				}
			}
			catch (Exception)
			{
				ElectricSystemCommand.AddShardParameters(this.uiDoc.Document, familyInstance, electricalSystem);
				csystemDataBlock.StrWireType = electricalSystem.GetParameter("导线类型").AsString();
				if (string.IsNullOrEmpty(csystemDataBlock.StrWireType))
				{
					csystemDataBlock.StrWireType = this.vecWireType[0];
				}
			}
			csystemDataBlock.NWireNum = 3;
			csystemDataBlock.StrLaying = electricalSystem.GetParameter("敷设方式").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrLaying))
			{
				csystemDataBlock.StrLaying = this.vecLayingMode[0];
			}
            List<double> wireSize = new List<double>();// this.data.GetWireSize(csystemDataBlock.StrWireType);
			csystemDataBlock.DWireS = wireSize[0];
			csystemDataBlock.StrPipeType = electricalSystem.GetParameter("穿管类型").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrPipeType))
			{
				csystemDataBlock.StrPipeType = this.vecPipeType[0];
			}
            double pipeSize = 0;// this.data.GetPipeSize(csystemDataBlock.StrWireType, (int)csystemDataBlock.NWireNum, csystemDataBlock.StrPipeType, csystemDataBlock.DWireS);
			double dpipeDia = this.FindProximal(csystemDataBlock.StrPipeType, pipeSize);
			csystemDataBlock.DPipeDia = dpipeDia;
			csystemDataBlock.StrSwitchName = electricalSystem.GetParameter("开关名称").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrSwitchName))
			{
				csystemDataBlock.StrSwitchName = this.vecLocalName[0];
			}
			csystemDataBlock.StrSwitchType = electricalSystem.GetParameter("开关型号").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrSwitchType))
			{
				csystemDataBlock.StrSwitchType = this.vecSwitchType[0];
			}
			double num9 = 0.0;
			CStandardManual.GetSwitchSpec(csystemDataBlock.StrSwitchType, csystemDataBlock.DIc, ref num9);
			csystemDataBlock.StrSwitchSpec = num9.ToString();
			csystemDataBlock.StrParentGUID = familyInstance.Id.ToString();
			this.powerList.Add(csystemDataBlock);
			bool flag = false;
			using (List<CSystemDataBlock>.Enumerator enumerator2 = this.allPowerAndPanel.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					if (enumerator2.Current.StrGUID == csystemDataBlock.StrGUID)
					{
						flag = true;
					}
				}
			}
			if (!flag)
			{
				this.allPowerAndPanel.Add(csystemDataBlock);
			}
		}

		private double FindProximal(string conduitType, double target)
		{
            //List<double> allWireWearPipe = this.data.GetAllWireWearPipe(conduitType);
			List<double> list = new List<double>();
            //double num = Math.Abs(target - allWireWearPipe[0]);
            //foreach (double num2 in allWireWearPipe)
            //{
            //    double num3 = Math.Abs(target - num2);
            //    if (num3 < num)
            //    {
            //        num = num3;
            //        list.Clear();
            //        list.Add(num2);
            //    }
            //    else if (num3 == num)
            //    {
            //        list.Add(num2);
            //    }
            //}
			return list[0];
		}

		private void GetDataOfPanel(Element element)
		{
			FamilyInstance familyInstance = element as FamilyInstance;
			CSystemDataBlock csystemDataBlock = new CSystemDataBlock();
			csystemDataBlock.M_object = element;
			csystemDataBlock.NDataType = 0;
			csystemDataBlock.StrGUID = familyInstance.Id.ToString();
			csystemDataBlock.StrNum = familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_NAME).AsString();
			csystemDataBlock.StrLoadType = this.uiDoc.Document.GetElementById(familyInstance.GetTypeId()).GetParameter("负荷分类").AsValueString();
			if (this.uiDoc.Document.GetElementById(familyInstance.GetTypeId()).GetParameter("极数").AsInteger() == 1)
			{
				bool flag = false;
				double num = familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEA).AsDouble();
				double num2 = familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEB).AsDouble();
				double num3 = familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD_PHASEC).AsDouble();
				if (num != 0.0)
				{
					flag = true;
					csystemDataBlock.StrPhase = "A";
				}
				if (!flag && num2 != 0.0)
				{
					flag = true;
					csystemDataBlock.StrPhase = "B";
				}
				if (!flag && num3 != 0.0)
				{
					flag = true;
					csystemDataBlock.StrPhase = "C";
				}
				if (!flag)
				{
					csystemDataBlock.StrPhase = "A";
				}
			}
			else if (this.uiDoc.Document.GetElementById(familyInstance.GetTypeId()).GetParameter("极数").AsInteger() == 3)
			{
				csystemDataBlock.StrPhase = "3P";
			}
			double num4 = 0.0;
			if (this.powerList.Count > 0)
			{
				for (int i = 0; i < this.powerList.Count; i++)
				{
					num4 += this.powerList[i].DPe;
				}
			}
			csystemDataBlock.DPe = num4;
			double value = (this.uiDoc.Document.GetElementById(familyInstance.GetTypeId()) as FamilySymbol).GetParameter("额定电压").AsDouble();
			csystemDataBlock.DUr = Math.Round(UnitConvert.CovertFromAPI((DisplayUnitType)84, value));
			csystemDataBlock.DKx = Math.Round(familyInstance.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_TOTAL_DEMAND_FACTOR_PARAM).AsDouble(), 2);
			double num7;
			double num8;
			if (csystemDataBlock.StrPhase == "3P")
			{
				List<double> list = new List<double>();
				List<double> list2 = new List<double>();
				List<double> list3 = new List<double>();
				List<double> list4 = new List<double>();
				for (int j = 0; j < this.powerList.Count; j++)
				{
					if (this.powerList[j].StrPhase != "3P")
					{
						double num5 = this.powerList[j].DKx * this.powerList[j].DPe;
						double item = num5 * (Math.Sqrt(1.0 - this.powerList[j].DCos * this.powerList[j].DCos) / this.powerList[j].DCos);
						list.Add(num5);
						list2.Add(item);
					}
					else
					{
						double item2 = this.powerList[j].DKx * this.powerList[j].DPe;
						double num6 = Math.Sqrt(1.0 - this.powerList[j].DCos * this.powerList[j].DCos) / this.powerList[j].DCos;
						list3.Add(item2);
						list4.Add(item2);
					}
				}
				num7 = list.Max() * 3.0 + list3.Sum();
				num8 = list2.Max() * 3.0 + list4.Sum();
				double num9 = Math.Sqrt(num7 * num7 + num8 * num8);
				csystemDataBlock.DIc = Math.Round(num9 / (Math.Sqrt(3.0) * csystemDataBlock.DUr), 2);
			}
			else
			{
				List<double> list5 = new List<double>();
				List<double> list6 = new List<double>();
				for (int k = 0; k < this.powerList.Count; k++)
				{
					if (this.powerList[k].StrPhase != "3P")
					{
						double num10 = this.powerList[k].DKx * this.powerList[k].DPe;
						double item3 = num10 * (Math.Sqrt(1.0 - this.powerList[k].DCos * this.powerList[k].DCos) / this.powerList[k].DCos);
						list5.Add(num10);
						list6.Add(item3);
					}
					else
					{
						double item4 = this.powerList[k].DKx * this.powerList[k].DPe;
						double num11 = Math.Sqrt(1.0 - this.powerList[k].DCos * this.powerList[k].DCos) / this.powerList[k].DCos;
						list5.Add(item4);
						list6.Add(item4);
					}
				}
				num7 = list5.Sum();
				num8 = list6.Sum();
				double num12 = Math.Sqrt(num7 * num7 + num8 * num8);
				csystemDataBlock.DIc = Math.Round(num12 / csystemDataBlock.DUr, 2);
			}
			csystemDataBlock.DCos = Math.Round(Math.Cos(Math.Atan(num8 / num7)), 2);
			csystemDataBlock.StrWireType = familyInstance.GetParameter("导线类型").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrWireType))
			{
				csystemDataBlock.StrWireType = this.vecWireType[0];
			}
			csystemDataBlock.NWireNum = 3;
            List<double> wireSize = new List<double>();// this.data.GetWireSize(csystemDataBlock.StrWireType);
			csystemDataBlock.DWireS = wireSize[0];
			csystemDataBlock.StrPipeType = familyInstance.GetParameter("穿管类型").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrPipeType))
			{
				csystemDataBlock.StrPipeType = this.vecPipeType[0];
			}
            double pipeSize = 0;// this.data.GetPipeSize(csystemDataBlock.StrWireType, (int)csystemDataBlock.NWireNum, csystemDataBlock.StrPipeType, csystemDataBlock.DWireS);
			double dpipeDia = this.FindProximal(csystemDataBlock.StrPipeType, pipeSize);
			csystemDataBlock.DPipeDia = dpipeDia;
			csystemDataBlock.StrLaying = familyInstance.GetParameter("敷设方式").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrLaying))
			{
				csystemDataBlock.StrLaying = this.vecLayingMode[0];
			}
			csystemDataBlock.StrSwitchName = familyInstance.GetParameter("开关名称").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrSwitchName))
			{
				csystemDataBlock.StrSwitchName = this.vecLocalName[0];
			}
			csystemDataBlock.StrSwitchType = familyInstance.GetParameter("开关型号").AsString();
			if (string.IsNullOrEmpty(csystemDataBlock.StrSwitchType))
			{
				csystemDataBlock.StrSwitchType = this.vecSwitchType[0];
			}
			double num13 = 0.0;
			CStandardManual.GetSwitchSpec(csystemDataBlock.StrSwitchType, csystemDataBlock.DIc, ref num13);
			csystemDataBlock.StrSwitchSpec = num13.ToString();
			string strParentGUID = "";
			ElectricalSystemSet electricalSystems = familyInstance.MEPModel.ElectricalSystems;
			if (electricalSystems != null)
			{
				foreach (object obj in electricalSystems)
				{
					strParentGUID = ((ElectricalSystem)obj).Id.ToString();
				}
			}
			csystemDataBlock.StrParentGUID = strParentGUID;
			bool flag2 = false;
			using (List<CSystemDataBlock>.Enumerator enumerator2 = this.allPowerAndPanel.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					if (enumerator2.Current.StrGUID == csystemDataBlock.StrGUID)
					{
						flag2 = true;
					}
				}
			}
			if (!flag2)
			{
				this.allPowerAndPanel.Add(csystemDataBlock);
			}
		}

		private UIDocument uiDoc;

        //private ElectricSystemSettingData data = new ElectricSystemSettingData();

		private List<CSystemDataBlock> allPowerAndPanel = new List<CSystemDataBlock>();

		private int isGetPara;

		private List<string> vecPipeType = new List<string>();

		private List<string> vecLayingMode = new List<string>();

		private List<string> vecLocalName = new List<string>();

		private List<string> vecSwitchType = new List<string>();

		private List<string> vecWireType = new List<string>();

		private string xmlFile = Path.Combine(new string[]
		{
			Product.WorkingLocation + "SystemGraph.xml"
		});

		private List<FindPowerAndPanel> equSet = new List<FindPowerAndPanel>();

		private List<CSystemDataBlock> powerList = new List<CSystemDataBlock>();

		private List<CSystemDataBlock> panelList = new List<CSystemDataBlock>();
	}
}
